package org.xxpay.pay.channel.bee138;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.xxpay.common.unify.AbstractPaymentConfig;

/**
 * @Package org.xxpay.pay.channel.bee138
 * @Class: Bee138Config.java
 * @Description: 优贝网关
 * @Author leo
 * @Date 2019/5/24 17:35
 * @Version
 **/
@Component
@Data
@ToString
@NoArgsConstructor
public class Bee138Config extends AbstractPaymentConfig {

    public static final String CHANNEL_NAME = "bee138";
    public static final String CHANNEL_NAME_BEE138 = CHANNEL_NAME + "_bee138";
    public static final String CHANNEL_NAME_QUICK = CHANNEL_NAME + "_quick";
    public static final String RETURN_VALUE_SUCCESS = "T";
    public static final String RETURN_VALUE_FAIL = "F"; // 失败返回码
    public static final String RESPONSE_RESULT_SUCCESS = "SUCCESS"; // 返回上游成功
    public static final String RESPONSE_RESULT_FAIL = "FAIL";       // 返回上游失败

    // ======================异步通知参数值=======================
    // 异步交易状态
    public final static String ASYNC_TRADE_STATUS = "SUCCESS";


    // =================上传参数默认值=================
    // 服务类型, 支付下单
    public static final String DEFAULT_SERVICE_TYPE = "direct_pay";
    public static final String DEFAULT_QUERY_ORDER_SERVICE_TYPE = "single_trade_query";
    // 接口版本号
    public static final String DEFAULT_VERSION = "V3.0";
    public static final String DEFAULT_INPUT_CHARSET = "UTF-8";
    // 签名方式
    public static final String DEFAULT_SIGN_TYPE = "RSA-S";
    // 是否允许重复订单
    //当值为1时不允许商户订单号重复提交；当值为 0或空时允许商户订单号重复提交
    public static final String DEFAULT_REDO_FLAG = "1";

    // 订单查询地址
    public static final String TRADE_QUERY_URL = "https://query.bee138.com/query";

    public static final String TRANSFER_URL = "https://transfer.bee138.com/transfer";

    /**
     * 转账的方式（0：普通  1：加急）
     */
    private String transType;

    public Bee138Config(String payParam) {
        Assert.notNull(payParam, "init bee138 config error");
        JSONObject object = JSON.parseObject(payParam);
        setMchId(object.getString("mchId"));
        setPrivateKey(object.getString("privateKey"));
        setPublicKey(object.getString("publicKey"));
        setRequestUrl(object.getString("requestUrl"));
        setPayMode(object.getString("type"));
        // 扣除手续费的方式：0：从转账金额中扣除  1：从账户余额中扣除
        setTradeRule(object.getString("tradeRule"));
        // 转账的方式（0：普通  1：加急）
        setTransType(object.getString("transType"));
    }


}
